const { BaseAction , RequestParser , RequestAuth } = require("breeze-web") 
const RedisAction = new BaseAction("redis")
const ParamOption = RequestParser.ParamOption

RedisAction.get({
    path : "/set" ,
    params :[
        ParamOption.String("key" , "key" , 2 , 10 ) ,
        ParamOption.String("value" , "value" , 1 , 40 )
    ]
} , async ctx => {

    const { key , value } = ctx.request.ps 
    const redis = ctx.Kit.redis 
    const result = await redis.setAsync( key , value )
    
    ctx.body = RedisAction.succ( "ok" , result )

})

RedisAction.get({
    path : "/get" ,
    params : [
        ParamOption.String("key" , "key" , 2 , 10 ) ,
    ]
} , async ctx => {
    const { key } = ctx.request.ps 
    const redis = ctx.Kit.redis 
    const value = await redis.getAsync( key )
    ctx.body = RedisAction.succ( value )
})

RedisAction.get({
    path : "/incr" ,
    params : [
        ParamOption.String("key" , "key" , 2 , 10 ) ,
    ]
} , async ctx => {
    const { key } = ctx.request.ps 
    const redis = ctx.Kit.redis 
    const value = await redis.incrbyAsync( key , 1 )
    ctx.body = RedisAction.succ( value )
})


module.exports = RedisAction